<template>
  <el-table-column align="center" :prop="prop" :label="label">
    <template slot-scope="scope">
      <span>{{ showText(scope.row[key]) }}</span>
    </template>
  </el-table-column>
</template>

<script>
export default {
  name: 'DictTextTableColumn',
  props: {
    key: {
      type: String,
      default: 'category'
    },
    prop: {
      type: String,
      default: ''
    },
    label: {
      type: String,
      default: ''
    },
    dicts: {
      type: Array,
      default: null
    }
  },
  data() {
    return {}
  },
  methods: {
    showText(code) {
      if (!this.dicts) {
        return ''
      }
      const cate = this.dicts.find(category => category.code === code)
      return (cate && cate.text) || ''
    }
  }
}
</script>
